﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Readme</title>
    <style>
        html, body {
            font-family: sans-serif;
        }
        code {
            font-family: monospace;
            font-size: 120%;
        }

        .page {
            max-width: 800px;
            margin: auto;
        }

        .note {
            background-color: #e4e4e4;
            padding: 4px;
            box-shadow: 0 0 5px #333;
        }

        .note:before {
            content: 'Note';
            background-color:deepskyblue;
            width: 100%;
            display: block;
            margin-left: -4px;
            margin-top: -4px;
            padding: 4px;
            font-weight: bold;
            margin-bottom: 4px;
        }
    </style>
</head>
<body>
    <div class="page">
        <h1>Crossfire API sample</h1>
        <p>Welcome to the Crossfire API sample, which shows how to use the Crossfire API.</p>
        <section>
            <h2>Installation</h2>
            <p>Make sure a driver with Crossfire API support is installed and that Crossfire is enabled in Radeon Settings.</p>
            <p class="note">If Crossfire is not enabled in Radeon Settings, the extension will not load, and the AGS_DX11_EXTENSION_CROSSFIRE_API flag will not be set.</p>
        </section>

        <section>
            <h2>How does the sample work?</h2>
            <p>The sample has a texture/render-target (<code>texture_</code>) which is updated in every <em>odd</em> frame by rendering into it. On a Crossfire system running in alternate frame rendering (AFR), the rendering will happen only on one GPU and hence the application will exhibit flickering.</p>
            <p>The Crossfire API solves this by allowing the developer to mark up the resource for copy.</p>
            <p>The Crossfire API consists of three main entry points:</p>
            <ul>
                <li><code>NotifyResourceBeginAllAccess</code>: Called before the first use of a resource. Ensures a copy is finished at this point.</li>
                <li><code>NotifyResourceEndWrites</code>: Called after the last write access to a resource. After this point, the resource can be copied.</li>
                <li><code>NotifyResourceEndAllAccess</code>: Called after the last read access to a resource. While a resource is being accessed, it cannot be updated from another GPU.</li>
            </ul>
            <p>Here's an illustration of the process. The boxes indicate frames, the orange area is the time between begin/end any access and the striped region is the time between begin and end write access. The left-hand side is the normal case, where the copy is initiated immediately after the write access has ended so it's available in time on the second GPU.</p>
            <p>The right-hand side illustrates why the <code>EndAnyAccess</code> is needed. Without it, the copy would overwrite the resource while it's still in use on GPU 0. With <code>EndAnyAccess</code>, it can be properly delayed until GPU 0 is done using it.</p>
            <figure style="width: 100%; text-align: center;">
                <img src="media/cfx-api.svg" style="width: 50%; margin: auto; background-color: white;">
            </figure>
        </section>
    </div>
</body>
</html>
